package com.dyh.quickdemo.future;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/*
@Author=Joey Wheeler
@Date=2021/4/21 17:54
*/
@Slf4j
public class TestFuture2 {



    @Test
    public void test1(){
        String str = "Cancellation error order XS0121041000003206403-1 prepared ;Cancellation error order XS0121041000003206403-1 prepared ;Cancellation error order XS0121041000003206403-1 prepared ;Cancellation error order XS0121041000003206403-1 prepared ;Cancellation e";

        System.out.println(str.length());

        System.out.println(str.contains("Cancellation error order XS0121041000003206403-1 prepared "));

        System.out.println("".length()>0);
    }

    @Test
    public void test11(){
        String str = "112";

        System.out.println(str.substring(0,2));

    }

    @Test
    public void test22(){
        StringBuilder sb = new StringBuilder();
        for (int i=0;i<256;i++){
            sb.append("1");
        }
        String str = sb.toString();
        if (str.length()>255)
            str = str.substring(0,255);
        System.out.println(str);
        System.out.println(str.length());
    }


    @Test
    public void test() throws ExecutionException, InterruptedException {

        ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(1024);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 15, 180, TimeUnit.SECONDS, queue);

        List<Future<String>> futures = new ArrayList<>();

        for (int i=0;i<5;i++){
            int finalI = i;
            Future future = threadPoolExecutor.submit(()->{
                String code = finalI+"";

                if (finalI ==2)
                    throw new RuntimeException(code);
                log.info(code);
                return code;
            });
            futures.add(future);
        }

        for (Future<String> future : futures) {
            future.get();
        }

    }
}
